package com.learng.springcloud.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Created by zhouwei on 2020/7/24.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultBean<T> {
    public static final int SUCCESS_CODE = 0;
    public static final int EXCEPTION_CODE = 500;
    int code;
    String msg;
    List<T> data;

    public static <T> ResultBean returnSuccess(List<T> testRestList) {
        ResultBean<T> resultBean = new ResultBean();
        resultBean.setCode(SUCCESS_CODE);
        resultBean.setData(testRestList);
        return resultBean;
    }

    public static ResultBean returnFail(Exception e){
        ResultBean response = new ResultBean<>();
        response.setCode(EXCEPTION_CODE);
        response.setMsg("系统异常:"+e.getMessage());
        return response;
    }
}
